home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / ada / gnat1792.zip / gnat179b / t-adainc / a-calend.ads < prev    next >
Text File  |  1994-05-19  |  5KB  |  106 lines

  1. ------------------------------------------------------------------------------
  2. --                                                                          --
  3. --                         GNAT RUNTIME COMPONENTS                          --
  4. --                                                                          --
  5. --                         A D A . C A L E N D A R                          --
  6. --                                                                          --
  7. --                                 S p e c                                  --
  8. --                                                                          --
  9. --                            $Revision: 1.7 $                              --
  10. --                                                                          --
  11. --           Copyright (c) 1992,1993,1994 NYU, All Rights Reserved          --
  12. --                                                                          --
  13. -- GNAT is free software;  you can  redistribute it  and/or modify it under --
  14. -- terms of the  GNU General Public License as published  by the Free Soft- --
  15. -- ware  Foundation;  either version 2,  or (at your option) any later ver- --
  16. -- sion.  GNAT is distributed in the hope that it will be useful, but WITH- --
  17. -- OUT ANY WARRANTY;  without even the  implied warranty of MERCHANTABILITY --
  18. -- or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License --
  19. -- for  more details.  You should have  received  a copy of the GNU General --
  20. -- Public License  distributed with GNAT;  see file COPYING.  If not, write --
  21. -- to the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. --
  22. --                                                                          --
  23. ------------------------------------------------------------------------------
  24.  
  25. package Ada.Calendar is
  26.  
  27.    type Time is private;
  28.  
  29.    --  Declarations representing limits of allowed local time values. Note that
  30.    --  these do NOT constrain the possible stored values of time which may well
  31.    --  permit a larger range of times (this is explicitly allowed in Ada 9X).
  32.  
  33.    subtype Year_Number  is Integer range 1901 .. 2099;
  34.    subtype Month_Number is Integer range 1 .. 12;
  35.    subtype Day_Number   is Integer range 1 .. 31;
  36.  
  37.    subtype Day_Duration is Duration; -- range 0.0 .. 86_400.0
  38.    --  We don't have subtype ranges yet for real types, fix this later ???
  39.  
  40.    function Clock return Time;
  41.  
  42.    function Year    (Date : Time) return Year_Number;
  43.    function Month   (Date : Time) return Month_Number;
  44.    function Day     (Date : Time) return Day_Number;
  45.    function Seconds (Date : Time) return Day_Duration;
  46.  
  47.    procedure Split
  48.      (Date    : Time;
  49.       Year    : out Year_Number;
  50.       Month   : out Month_Number;
  51.       Day     : out Day_Number;
  52.       Seconds : out Day_Duration);
  53.  
  54.    function Time_Of
  55.      (Year    : Year_Number;
  56.       Month   : Month_Number;
  57.       Day     : Day_Number;
  58.       Seconds : Day_Duration := 0.0)
  59.       return    Time;
  60.  
  61.    function "+" (Left : Time;     Right : Duration) return Time;
  62.    function "+" (Left : Duration; Right : Time)     return Time;
  63.    function "-" (Left : Time;     Right : Duration) return Time;
  64.    function "-" (Left : Time;     Right : Time)     return Duration;
  65.  
  66.    function "<"  (Left, Right : Time) return Boolean;
  67.    function "<=" (Left, Right : Time) return Boolean;
  68.    function ">"  (Left, Right : Time) return Boolean;
  69.    function ">=" (Left, Right : Time) return Boolean;
  70.  
  71.    Time_Error : exception;
  72.  
  73. private
  74.    pragma Inline (Clock);
  75.  
  76.    pragma Inline (Year);
  77.    pragma Inline (Month);
  78.    pragma Inline (Day);
  79.  
  80.    pragma Inline ("+");
  81.    pragma Inline ("-");
  82.  
  83.    pragma Inline ("<");
  84.    pragma Inline ("<=");
  85.    pragma Inline (">");
  86.    pragma Inline (">=");
  87.  
  88.    --  Time is represented as a signed duration from the base point which is
  89.    --  what Unix calls the EPOCH (i.e. 12 midnight (24:00:00), Dec 31st, 1969,
  90.    --  or if you prefer 0:00:00 on Jan 1st, 1970). Since Ada allows dates
  91.    --  before this EPOCH value, the stored duration value may be negative.
  92.  
  93.    --  The time value stored is typically a GMT value, as provided in standard
  94.    --  Unix environments. If this is the case then Split and Time_Of perform
  95.    --  required conversions to and from local times. The range of times that
  96.    --  can be stored in Time values depends on the declaration of the type
  97.    --  Duration, which must at least cover the required Ada range represented
  98.    --  by the declaration of Year_Number, but may be larger (we take full
  99.    --  advantage of the new permission in Ada 9X to store time values outside
  100.    --  the range that would be acceptable to Split). The Duration type is a
  101.    --  real value representing a time interval in seconds.
  102.  
  103.    type Time is new Duration;
  104.  
  105. end Ada.Calendar;
  106.